/**
 * 
 */$(function(){
	 $("#"+tabId+" .date-from").datetimepicker({
		   format: "yyyy-mm",
	       autoclose: true,
	       todayBtn: true,
	       minView: 3,
	       startView:3,
	       language: 'zh-CN'
	   });
	$("#"+tabId+" .date-to").datetimepicker({
	       format: "yyyy-mm",
	       autoclose: true,
	       todayBtn: true,
	       minView: 3,
	       startView:3,
	       language: 'zh-CN'
	   });
	$("#"+tabId+" .date-from").val(drgsDate.dateFrom.substring(0,7));
	$("#"+tabId+" .date-to").val(drgsDate.dateTo.substring(0,7));
	
	   $('#'+tabId+' #date_type input').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	   });
	   $("#"+tabId+" #sum_expense_id").on("click",function(){
		$("#" + tabId+" #sum_expense_id").html("正在计算……");
		$("#" + tabId+" #sum_expense_id").attr("disabled","");
		$.post(contextPath + "/systemConfig/sumExpense.dhc",
			{ dateFrom:$("#"+tabId+" #exe_date_from").val(), 
			dateTo:$("#"+tabId+" #exe_date_to").val(),
			dateType:$('#'+tabId+' input:radio[name="dateType"]:checked').val()}).done(function(result){
				$(document).ajaxStop(function(){
				});
				$("#" + tabId+" #sum_expense_id").html("计算");
						$("#" + tabId+" #sum_expense_id").removeAttr("disabled");
				drgUI.success("计算并更新成功！") ;
		});
	});
	
	$("#" + tabId + " #oper_id").on("click", function() {
		$("#" + tabId+" #oper_id").html("正在更新……");
		$("#" + tabId+" #oper_id").attr("disabled","");
		$.post(contextPath + "/matchIcd/updateMrIsOper.dhc", {
					dateFrom : $("#" + tabId + " #oper_date_from").val(),
					dateTo : $("#" + tabId + " #oper_date_to").val()
				}).done(function(result) {
					$(document).ajaxStop(function() {
						$("#" + tabId + " #oper_id").html("更新");
						$("#" + tabId + " #oper_id").removeAttr("disabled");
					});
					drgUI.success("更新成功!") ;
				})
	});
		/**
		 * 处理特殊字符
		 */	
	   $("#" + tabId + " #get_speccode_id").on("click", function() {
				 $(this).html("正在处理……");
				 $(this).attr("disabled","");
				 $.post(contextPath + "/systemConfig/handelSpecCode.dhc").done(function(result) {
							$(document).ajaxStop(function() {
								$("#" + tabId + " #get_speccode_id").html("处理");
								$("#" + tabId + " #get_speccode_id").removeAttr("disabled");
							});
						   drgUI.success("更新成功!") ;
						})
			});
/**			
 * 医嘱明细抽取类型切换
 */
$('#'+tabId+' #get_advice_type').on('change',function(){
	if($(this).val()=='out_date'){
		$('#out_date_type').css('display','');
		$('#mr_id_type').css('display','none');
	}else{
		$('#out_date_type').css('display','none');
		$('#mr_id_type').css('display','');
	}
  });
/**
 * 
 */
$('#'+tabId+' #get_advice_id').click(function(){
		var type=$('#'+tabId+' #get_advice_type').val();
		$(this).html('正在抽取数据...');
		$(this).attr("disabled","disabled");
		if(type=='out_date'){
			$.post(contextPath + "/order/orderImport.dhc",{'dateFrom':$('#'+tabId+' #advice_date_from').val(),'dateTo':$('#'+tabId+' #advice_date_to').val()}).done(
					function(result) {
						if(result.success){
							$('#'+tabId+' #get_advice_id').html('抽取');
							$('#'+tabId+' #get_advice_id').removeAttr("disabled");
						}else{
							drgUI.error(result.actionError);
							$('#'+tabId+' #error_id').html("错误信息"+result.actionError);
							$('#'+tabId+' #get_advice_id').html('抽取');
							$('#'+tabId+' #get_advice_id').removeAttr("disabled");
						}
					});
		}else{
			$.post(contextPath + "/order/orderImportByRecordId.dhc",{'recordId':$('#'+tabId+' #mr_id').val()}).done(
					function(result) {
						if(result.success){
							$('#'+tabId+' #get_advice_id').html('抽取');
							$('#'+tabId+' #get_advice_id').removeAttr("disabled");
						}else{
							drgUI.error(result.actionError);
							$('#'+tabId+' #get_advice_id').html('抽取');
							$('#'+tabId+' #get_advice_id').removeAttr("disabled");
						}
					});
		}
 });


	// 同步首页和医师表中的医师数据
	$("#"+tabId+" #updateDocCode").click(function(){
		keepIpinfoAndClinicGroup($(this)) ;
	});
})
 /**
  * 更新未入组原因
  * @returns
  */
 function upDateNotInReason() {
			var dateFrom = $("#" + tabId + " #rea_date_from").val();
			var dateTo = $("#" + tabId + " #rea_date_to").val();	
				$("#" + tabId+" #rea_id").html("正在更新……");
				$("#" + tabId+" #rea_id").attr("disabled","");
			$.post(contextPath + "/drgServiceGroup/updateNotInReason.dhc",{'dateFrom':dateFrom,'dateTo':dateTo}).done(
					function(result) {
						$("#" + tabId+" #rea_id").html("更新原因");
						$("#" + tabId+" #rea_id").removeAttr("disabled");
						$("#" + tabId+" #percentbar").css("display","none");
					});
		}
 
 /**
  * 查询首页表中医师编码的缺失情况
  * @
  * @void
  * @ Discription:
  * @updateDataPage.js
  */
 function findCaseCntDocCodeIsNull() {
	 var dateFrom = $("#" + tabId + " #docDateFrom").val();
	 var dateTo = $("#" + tabId + " #docDateTo").val();
	 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
		var dialog  = $(data);
		dialog.find(".echartscq").css({height:""});
		dialog.find(".modal-title").html("首页医师编码缺失统计");
		dialog.modal({
			keyboard: false
		}).on({
				'hidden.bs.modal' : function(){
					$(this).remove();
				},
				'shown.bs.modal' : function(){
					var str = '<table id="ipinfoDocCodeNullTable" class="table table-striped" width="100%"><caption style="font-size:14px"><strong>首页医师编码缺失统计</strong></caption></table>' ;
					dialog.find(".echartscq").html(str) ;
					$.post(contextPath + "/ClinicGroup/findCaseCntDocCodeIsNull.dhc",{'dateFrom':dateFrom,'dateTo':dateTo}).done(function(result){
						 var columns=[
						               	{"data": "YEARANDMONTH","title":"时间"} ,
						               	{"data": "CASECNT","title":"医师编码缺失病例"} ,
						               	{"data": "DEPMASTER","title":"科主任编码"} ,
						               	{"data": "PROTOMEDICUS","title":"主任医师编码"} ,
						               	{"data": "PHYSICIAN","title":"主治医师编码"} ,
						               	{"data": "RESIDENT","title":"住院医师编码"} ,
						               	{"data": "CLINIC","title":"主诊组编码"} ,
						               	{"data": "OPERATOR","title":"术者编码"} ,
						               	{"data": "ASSISTONE","title":"一助编码"} ,
						               	{"data": "ASSISTTWO","title":"二助编码"} ,
						              ]
						 var paramsDataTables={searching:true,ordering:true,stateSave:true,scrollX:true,tableTitle: "" };
							//使表头只展示一行
							dialog.find("#ipinfoDocCodeNullTable").dataTableBasic(columns,result.data,paramsDataTables) ;
					 })
				}
			})
	 })
	 
 }
 
 /**
  * 同步首页和医师表中的医师信息
  * @
  * @void
  * @ Discription:
  * @updateDataPage.js
  */
 function keepIpinfoAndClinicGroup($this) {
	 var dateFrom = $("#" + tabId + " #docDateFrom").val();
	 var dateTo = $("#" + tabId + " #docDateTo").val();
		drgUI.confirm({
		content : '确认更新吗?',
		callSure : function() {
			$this.text("正在更新...") ;
			 $this.attr("disabled","disabled") ;
			try {
				$.post(contextPath + "/ClinicGroup/keepIpinfoAndClinicGroup.dhc",{'dateFrom':dateFrom,'dateTo':dateTo}).done(function(result){
					$this.removeAttr("disabled") ;
						if(result.success) {
							drgUI.success("更新成功") ;
							$this.text("更新") ;
							$this.removeAttr("disabled") ;
							findCaseCntDocCodeIsNull() ;
						} else {
							drgUI.error("更新失败") ;
							$this.text("更新") ;
							$this.removeAttr("disabled") ;
						}
				 })
			} catch (e) {
				console.log(e)
				$this.text("更新") ;
				$this.removeAttr("disabled") ;
			}
		}
	});
 }